<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	重置记录
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	//奖品名称
	$return['params']=array();
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
		$return['params']['createtime']=$time_range;
	}
	$orderby='id desc';
	$list=pdo_getslice('core_recharge',$params,array($pindex,$psize),$total,array(),'',$orderby);
	if($list){
		foreach($list as &$item){
			$item['member']=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('nickname','avatar'));
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>array(
			array('op'=>'list','title'=>'充值记录'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('name'=>'member.nickname','title'=>'会员昵称','type'=>'string'),
			array('name'=>'member.avatar','title'=>'会员头像','type'=>'image'),
			array('name'=>'fee','title'=>'充值金额','type'=>'string'),
			array('name'=>'status','title'=>'是否支付','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'充值时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'mid','width'=>15,'title'=>'会员id','type'=>'choose','action'=>'core/member.get_member/'),
			array('name'=>'createtime','width'=>15,'title'=>'发生时间','type'=>'time_range'),
		)
	);
	$return['status']=array('未支付','已支付');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	//创建时间
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$list=pdo_getall('core_recharge',$params);
	if($list){
		foreach($list as &$item){
			$item['member']=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('nickname','avatar'));
			$item['nickname']=$member['nickname'];
			$item['status']=$item['status']==1?'已支付':'未支付';
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		}
	}
	$header=array(
		'nickname'=>'用户昵称',
		'fee'=>'充值金额',
		'status'=>'是否支付',
		'createtime'=>'充值时间',
	);
	cfc('tools')->export2excel($header,$list,'充值日志');
}
if($_RQ['op']=='del'){
	//删除奖品
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('core_recharge',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('core_recharge',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}